package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.MarketBrand;
import com.cskaoyan.model.admin.bo.BaseParam;
import com.cskaoyan.model.admin.vo.BaseData;
import com.cskaoyan.model.admin.vo.BaseRespVo;
import com.cskaoyan.service.admin.BrandByChenService;
import com.cskaoyan.utils.UserControllerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: Zhuqi
 * @Date: 2021/11/30 16:26
 * @Description: 品牌制造商的controller
 */
@RestController
public class BrandByChenController {
    @Autowired
    BrandByChenService brandByChenService;

    /**
     * @Author ChenZhuqi
     * @Date 2021/11/30 16:32
     * @Description： brand list显示商品的列表,查找商品
     */

    @RequestMapping("admin/brand/list")
    public BaseRespVo list(BaseParam param, String id, String name) {
        //调用了工具类
        UserControllerUtils userControllerUtils = new UserControllerUtils();
        if (userControllerUtils.userIdOfLegal(id) == 0) {
            return BaseRespVo.fail(402, "参数值不对");
        }

        BaseData data = brandByChenService.list(param, id, name);
        return BaseRespVo.ok(data);
    }

    /**
     * @Author ChenZhuqi
     * @Date 2021/11/30 16:51
     * @Description： create 商品添加
     */
    @PostMapping("admin/brand/create")
    public BaseRespVo brandCreate(@RequestBody MarketBrand brand) {

        MarketBrand marketBrand = brandByChenService.brandCreate(brand);
        return BaseRespVo.ok(marketBrand);
    }


    /**
     * @Author ChenZhuqi
     * @Date 2021/11/30 22:23
     * @Description： 商品编辑
     */
    @PostMapping("admin/brand/update")
    public BaseRespVo brandUpdate(@RequestBody MarketBrand brand) {

        MarketBrand marketBrand = brandByChenService.brandUpdate(brand);
        return BaseRespVo.ok(marketBrand);
    }
     /**
      * @Author ChenZhuqi
      * @Date 2021/11/30 22:55
      * @Description： 商品删除
      */
     @PostMapping("admin/brand/delete")
     public BaseRespVo brandDelete(@RequestBody MarketBrand brand){
         MarketBrand marketBrand = brandByChenService.brandDelete(brand);
         return BaseRespVo.ok(marketBrand);
     }

}
